package java2D.engine;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.image.BufferStrategy;

import javax.swing.JFrame;


public class Window extends JFrame {

	private double offx=0;
	
	private long rt;
	private BufferStrategy bufstrat;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -6256225719726000919L;

	public Window()
	{
		super();
		this.setResizable(false);		
		this.setDefaultCloseOperation(Window.EXIT_ON_CLOSE);
		this.setSize(500, 500);
		//this.setUndecorated(true);
		this.setVisible(true);
		this.createBufferStrategy(4);
		bufstrat = this.getBufferStrategy();
	}
	
	public void update(long refreshtime)
	{
		this.rt = refreshtime;
		offx += ((double)refreshtime/ (double)50);
		offx %= 100;
		//System.out.println(offx);
		//System.out.println(refreshtime);
	}
	
	public void draw()
	{
		do{
			do{
				Graphics2D g2d = (Graphics2D) bufstrat.getDrawGraphics();
				g2d.setBackground(Color.white);
				g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
				char[] chars = String.valueOf(rt).toCharArray();
				
				g2d.clearRect(0, 0, 250, 250);
				g2d.drawChars(chars, 0, chars.length, 50, 50);
				g2d.drawRect((int)(25 + offx),(int)(125 - offx), 100, 100);
				g2d.dispose();
			}while(bufstrat.contentsRestored());
			
			bufstrat.show();
			
		}while(bufstrat.contentsLost());
		
		Toolkit.getDefaultToolkit().sync();
	}
	
	/*
	@Override
	public void paint(Graphics g)
	{
		Graphics2D g2d = (Graphics2D) g;
		g2d.setBackground(Color.white);
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		char[] chars = String.valueOf(rt).toCharArray();

		g2d.clearRect(0, 0, 250, 250);
		g2d.drawChars(chars, 0, chars.length, 50, 50);
		g2d.drawRect((int)(25 + offx),(int)(125 - offx), 100, 100);
	}*/
	
	
}
